package geo.com.geosdkdemo.view.activity;

import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import org.greenrobot.eventbus.EventBus;

import java.util.ArrayList;

import geo.com.geosdk.GeoManage;
import geo.com.geosdk.modelsetting.BaseModel.BaseWorkingModeParameter;
import geo.com.geosdk.modelsetting.GeneralBean.DataLinkParameter;
import geo.com.geosdk.modelsetting.StatisModel.StaticWorkingModeParameter;
import geo.com.geosdkdemo.event.DialogDismissEvent;
import geo.com.geosdkdemo.view.adapter.SelectDialogAdapter;
import geo.com.geosdkdemo.R;

import static geo.com.geosdkdemo.view.activity.BaseSetupActivity.ISBASE;
import static geo.com.geosdkdemo.view.activity.RoverSetupActivity.DIALOGNAME;
import static geo.com.geosdkdemo.view.activity.RoverSetupActivity.MOUNTPOINTS;


public class SelectDialogActivity extends Activity {
    private BaseWorkingModeParameter baseWorkingModeParameter=GeoManage.getInstance().getBaseWorkingModeParameter();
    private DataLinkParameter dataLinkParameter = GeoManage.getInstance().getDataLinkParameter();
    private StaticWorkingModeParameter staticWorkingModeParameter=GeoManage.getInstance().getStaticWorkingModeParameter();
    private TextView tvTitle;
    private ListView listView;
    private RelativeLayout rlParent;
    private SelectDialogAdapter adapter;
    private ArrayList<String> arrayList;
    private String title;
    private ArrayList<String> mountPoints;
    private boolean isBase=false;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_activity_ellipsoid_select_dialog);
        tvTitle=findViewById(R.id.title);
        listView=findViewById(R.id.listview);

        arrayList=new ArrayList<>();
        title=getIntent().getStringExtra(DIALOGNAME);
        isBase=getIntent().getBooleanExtra(ISBASE,false);
        mountPoints=getIntent().getStringArrayListExtra(MOUNTPOINTS);
        tvTitle.setText(title);

        if(title.equals("数据链") && isBase){//移动站的数据链
            arrayList.add("主机网络");
            arrayList.add("内置电台");
            arrayList.add("外置电台");
        }if(title.equals("数据链") && !isBase){
            arrayList.addAll(dataLinkParameter.mDataLinkType.getTypeTitles());
        }else if(title.equals("连接模式")){
            arrayList.addAll(dataLinkParameter.mNetwork.mConnectionMode.getTypeTitles());
        }else if(title.equals("通道")){
            for(int i=1;i<=8;i++){
                arrayList.add(String.valueOf(i));
            }
        }else if(title.equals("协议")){
            //UHFProtocolType.getTypeTitles()获取UHFProtocolType类型里面的名称
            arrayList.addAll(dataLinkParameter.mUHF.mUhfProtocolType.getTypeTitles());
        }else if(title.equals("启动模式")){
            arrayList.addAll(baseWorkingModeParameter.mBaseStartupType.getTypeTitles());
        }else if(title.equals("差分模式")){
            arrayList.addAll(baseWorkingModeParameter.mDifType.getTypeTitles());
        }else if(title.equals("天线量取方式")){
            arrayList.addAll(staticWorkingModeParameter.mAntenna.mAntennaMeasureMode.getTypeTitles());
        }else if(title.equals("接入点")){
            arrayList.addAll(mountPoints);
        }

        adapter=new SelectDialogAdapter(this,arrayList);
        listView.setAdapter(adapter);

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                adapter.setCurrentItem(position);
                adapter.setClick(true);
                //刷新这个才能重新执行getView方法
                adapter.notifyDataSetChanged();
                EventBus.getDefault().post(new DialogDismissEvent(title,arrayList.get(position)));
                finish();
            }
        });
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }
}
